#pragma once
#include "common.h"

class PageCache
{
public:
    static PageCache* GetInstance()
    {
        return& _sInstance;
    }
    //获取页号与span的映射
    Span* MapObjectToSpan(void* obj);
    //释放span回page cache
    void ReleaseSpanToPageCache(Span* span);
    //获取一个PageNum页的span
    Span* NewSpan(size_t pageNum);
    //page cache的整体锁
    std::mutex _pageMutex;
private:
    SpanList _spanLists[NPAGES];//按桶号映射，第i桶里的span都是i页内存
    std::unordered_map<PAGE_ID, Span*> _idSpanMap;//页号和span的映射表
    ObjectPool<Span> _spanPagePool;//用于获取span

    PageCache(){}
    PageCache(const PageCache&) = delete;
    static PageCache _sInstance;//类内声明
};